﻿using Device.API.Applcation.Command.UnitCommand;
using Device.Infrstructre.Interface;
using MediatR;

namespace Device.API.Applcation.CommandHandlers.UnitCommandHandlers
{
    /// <summary>
    /// 单位管理删除
    /// </summary>
    public class DelUnitCommandHandlers : IRequestHandler<DelUnitCommand, int>
    {
        private readonly IUnitRepository _unitRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="unitRepository"></param>
        public DelUnitCommandHandlers(IUnitRepository unitRepository)
        {
            _unitRepository = unitRepository;
        }

        public async Task<int> Handle(DelUnitCommand request, CancellationToken cancellationToken)
        {
            var list = await _unitRepository.GetModelAsync(request.UnitId);//根据id找到要删除的数据
            list.IsDel = true;//逻辑删除
            list.DelName = request.DelName;//删除人姓名
            list.DelTime = request.DelTime;//删除人时间
            return await _unitRepository.UpdateAsync(list);//修改
        }
    }
}
